package com.hospital.hospitalsystem.modules.login.controller;

import com.hospital.hospitalsystem.base.BaseResponse;
import com.hospital.hospitalsystem.config.TokenVerify;
import com.hospital.hospitalsystem.modules.login.biz.LoginBiz;
import com.hospital.hospitalsystem.modules.login.dto.*;
import com.hospital.hospitalsystem.utils.LoginUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author qiancheng@cqxyy.net
 * @date 2023/2/21
 */
@RestController
@RequestMapping("/login")
@Api(tags = "登录管理")
@Validated
public class LoginController {

    @Autowired
    private LoginBiz loginBiz;

    @Autowired
    private LoginUtils loginUtils;

    @ApiOperation(value = "用户注册")
    @RequestMapping(path = "/register/user",method = RequestMethod.POST)
    public BaseResponse userRegister(@RequestBody UserRegisterReq req){
        loginBiz.userRegister(req);
        return BaseResponse.success();
    };

    @ApiOperation(value = "医院注册")
    @RequestMapping(path = "/register/hospital",method = RequestMethod.POST)
    public BaseResponse hospitalRegister(@RequestBody HospitalRegisterReq req){
        loginBiz.hospitalRegister(req);
        return BaseResponse.success();
    };

    @ApiOperation(value = "用户登录")
    @RequestMapping(path = "/login",method = RequestMethod.POST)
    public BaseResponse login(@RequestBody UserLoginReq req){
        LoginRsp loginRsp = loginBiz.login(req);
        return BaseResponse.success(loginRsp);
    };

    @ApiOperation(value = "发送电子邮件")
    @RequestMapping(path = "/send-email",method = RequestMethod.POST)
    public BaseResponse verification(@RequestBody SendEmailReq req){
        loginBiz.sendEmail(req);
        return BaseResponse.success();
    };

    @ApiOperation(value = "用户注销")
    @RequestMapping(path = "/delete",method = RequestMethod.POST)
    public BaseResponse deleteCount(@RequestBody DeleteCountReq req){
        if (StringUtils.isBlank(req.getUuid())) {
            req.setUuid(loginUtils.getUser().getUserUuid());
        }
        loginBiz.deleteCount(req);
        return BaseResponse.success();
    };
}
